package com.example.demo.main.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author xieluoyin
 *  2018/8/5 18:46
 */
public class RabbitmqConnectionUtil {
    public static Connection getConnection() throws Exception {
        // 创建一个ConnectionFactory, 并进行配置
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("test");
        connectionFactory.setPassword("test");
        connectionFactory.setVirtualHost("/test");
        //Recovery n. 恢复，复原；痊愈；重获
        connectionFactory.setAutomaticRecoveryEnabled(true);
        connectionFactory.setNetworkRecoveryInterval(3000);
        return connectionFactory.newConnection();

    }
}
